package com.hivekion.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hivekion.system.domain.SysUserAreas;
import com.hivekion.system.mapper.SysUserAreasMapper;
import com.hivekion.system.service.ISysUserAreasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 */
@Service
public class ISysUserAreasServiceImpl extends ServiceImpl<SysUserAreasMapper, SysUserAreas> implements ISysUserAreasService {
      @Autowired
      private SysUserAreasMapper sysUserAreasMapper;

      @Override
      public SysUserAreas queryAreaByUserId(String userId) {
	    LambdaQueryWrapper<SysUserAreas> queryWrapper = Wrappers.lambdaQuery();
	    queryWrapper.eq(SysUserAreas::getUserId, userId);
	    return sysUserAreasMapper.selectOne(queryWrapper);
      }

      @Override
      public List<SysUserAreas> queryUserIdsByAreas(String pathIds) {
	    LambdaQueryWrapper<SysUserAreas> queryWrapper = Wrappers.lambdaQuery();
	    String[] split = pathIds.split(",");

	    if (split.length <= 0) {
		  return null;
	    }
	    int i = 0;
	    for (String pathId : split) {
		  queryWrapper.eq(SysUserAreas::getAreaId, pathId);
		  if (i < split.length - 1) {
			queryWrapper.or();
		  }
		  i = i + 1;
	    }

	    return sysUserAreasMapper.selectList(queryWrapper);
      }
}
